//
//  DYWBottomView.swift
//  sinaWeibo
//
//  Created by 董艳武 on 16/2/20.
//  Copyright © 2016年 董艳武. All rights reserved.
//

import UIKit
import SnapKit

class DYWBottomView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        setUpUI()
    }
    
    lazy var tranformBtn:UIButton = UIButton(img: "timeline_icon_retweet", bgImg: nil, title: "转发", titleFontSize: 10, titleColor: UIColor.blackColor())
    
    lazy var commentBtn:UIButton = UIButton(img: "timeline_icon_comment", bgImg: nil, title: "评论", titleFontSize: 10, titleColor: UIColor.blackColor())
    
    lazy var likeBtn:UIButton = UIButton(img: "timeline_icon_unlike", bgImg: nil, title: "赞", titleFontSize: 10, titleColor: UIColor.blackColor())
    
    lazy var sepLine1:UIView = UIView()
    
    lazy var sepLine2:UIView = UIView()
    
    private func setUpUI () {
        backgroundColor = LightBlue
        addSubview(tranformBtn)
        addSubview(sepLine1)
        addSubview(commentBtn)
        addSubview(sepLine2)
        addSubview(likeBtn)
        
        sepLine1.backgroundColor = UIColor.blackColor()
        sepLine2.backgroundColor = UIColor.blackColor()

        
        let equalWidth:CGFloat = (self.frame.width - 4 * commonMargin) / 3
        
        tranformBtn.snp_makeConstraints { (make) -> Void in
            make.width.equalTo(equalWidth)
            make.left.equalTo(self.snp_left).offset(commonMargin)
            make.centerY.equalTo(self.snp_centerY)
        }
        commentBtn.snp_makeConstraints { (make) -> Void in
            make.width.equalTo(tranformBtn.snp_width)
            make.left.equalTo(tranformBtn.snp_right).offset(commonMargin)
            make.centerY.equalTo(self.snp_centerY)
        }
        likeBtn.snp_makeConstraints { (make) -> Void in
            make.right.equalTo(self.snp_right).offset(-commonMargin)
            make.width.equalTo(commentBtn.snp_width)
            make.centerY.equalTo(self.snp_centerY)
        }
        sepLine1.snp_makeConstraints { (make) -> Void in
            make.width.equalTo(0.5)
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            make.left.equalTo(tranformBtn.snp_right).offset(commonMargin * 0.5)
            make.centerY.equalTo(self.snp_centerY)
        }
        sepLine2.snp_makeConstraints { (make) -> Void in
            make.width.equalTo(sepLine1.snp_width)
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            make.left.equalTo(commentBtn.snp_right).offset(commonMargin * 0.5)
            make.centerY.equalTo(self.snp_centerY)
            
        }
        tranformBtn.addTarget(self, action: "didClickToRetweetWeibo", forControlEvents: .TouchUpInside)
    }
    
    /// 转发按钮的点击事件
    @objc private func didClickToRetweetWeibo() {
    
        print(__FUNCTION__)
        
        let vc = DYWTempController()
        
        // 不修改背景颜色跳转时会有卡顿 设置 vc 的背景颜色为 whiteColor 就不会出现这个问题
        vc.view.backgroundColor = UIColor.whiteColor()
        print(vc.view.backgroundColor)
    
        // push 到导航栏控制器的时候 UITabBar 隐藏
//        vc.hidesBottomBarWhenPushed = true
        
        self.navgiationcontroller()?.pushViewController(vc, animated: true)
    
    
    }

}
